﻿
     using DigDes.DSchool.SUPS.DataAccess.Interface;
 using System;
	 using System.Collections.Generic;
	 using System.Configuration;
	 using System.Data.SqlClient;
	 using System.Linq;
 using System.Text;
	 using System.Threading.Tasks;
	  
	 namespace DigDes.DSchool.SUPS.DataAccess.Database
	 {
	     public class FileLoaderDAC
	     {
        // TODO: вынести общий функционал для подобных классов доступа к БД в общий класс BaseDAC
  
	         // Сама строка хранится в app.config (web.config) файле исполняемого файла, который дёрнет метод этой библиотеки классов.
         // В нашем случае это DigDes.DSchool.SUPS.Test.App файл App.Config.
	  
	         private static readonly string ConnectionStringKey = "SUPSDB2"; 
	  
	         public static void DoSomething(MyLoader1DTO row)
	         {
	             var connectionString = ConfigurationManager.ConnectionStrings[ConnectionStringKey].ConnectionString;
	             using (var sqlConn = new SqlConnection(connectionString))
	             {
	                 using (var sqlCmd = sqlConn.CreateCommand())
	                 {
	                     sqlCmd.CommandText = "insert into tbDislocation" +
                                          "([InventoryCarriageNumber],  [WeightTons],[DestinationStation],[CargoCodeTariff]," +
                                          "[ConsigneeCode], [ParkType],  [StartStation],     [OperationCode]," +
                                              "[OperationDate], [OperationYear], [OperationTime], [StationOfOperation], [DeliveryRoad], " +
                                              "[ReceiptRoad], [TrainIndex],[TrainNumber] ) " +
	                                          " values " +
	                                          "(@InventoryCarriageNumber, @WeightTons, @DestinationStation, @CargoCodeTariff, @СonsigneeCode,"+
	                                          "@ParkType, @StartStation, @OperationCode, @OperationDate, @OperationYear, @OperationTime, " +
	                                          "@StationOfOperation, @DeliveryRoad, @ReceptionRoad, @TrainIndex,@TrainNumber)"; 
	  
	                     sqlCmd.Parameters.AddWithValue("@InventoryCarriageNumber",row.InventoryCarriageNumber );
	                     sqlCmd.Parameters.AddWithValue("@WeightTons",row.WeightTons );
                         sqlCmd.Parameters.AddWithValue("@DestinationStation", row.DestinationStation);
	                     sqlCmd.Parameters.AddWithValue("@CargoCodeTariff",row.CargoCodeTariff );
	                     sqlCmd.Parameters.AddWithValue("@СonsigneeCode",row.СonsigneeCode );
	                     sqlCmd.Parameters.AddWithValue("@ParkType",row.ParkType );
                     sqlCmd.Parameters.AddWithValue("@StartStation",row.StartStation );
	                     sqlCmd.Parameters.AddWithValue("@OperationCode",row.OperationCode );
	                     sqlCmd.Parameters.AddWithValue("@OperationDate",row.OperationDate );
	                     sqlCmd.Parameters.AddWithValue("@OperationYear",row.OperationYear);
                     sqlCmd.Parameters.AddWithValue("@OperationTime",row.OperationTime);
	                     sqlCmd.Parameters.AddWithValue("@StationOfOperation",row.StationOfOperation);
	                     sqlCmd.Parameters.AddWithValue("@DeliveryRoad",row.DeliveryRoad);
                     sqlCmd.Parameters.AddWithValue("@ReceptionRoad",row.ReceptionRoad);
                     sqlCmd.Parameters.AddWithValue("@TrainIndex",row.TrainIndex);
                     sqlCmd.Parameters.AddWithValue("@TrainNumber", row.TrainNumber);
	                     sqlConn.Open();
	                     sqlCmd.ExecuteNonQuery();
	  
	                 }
	             }
	         }
	         public static void DoSomething2(IEnumerable<MyLoader1DTO> rows)
	         {
	             // Делается по аналогии с предыдущим методом
	             throw new NotImplementedException();
	         }
	     }
	 }
	  
 	  